<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<c:choose>
    <c:when test="${industryServiceInformation.new}"><c:set var="method" value="post"/></c:when>
    <c:otherwise><c:set var="method" value="put"/></c:otherwise>
</c:choose>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>浙江孵化器在线后台管理系统</title>
    <link href="<spring:url value="/static/style/index.css" htmlEscape="true" />" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="<spring:url value="/static/js/jquery.min.js" htmlEscape="true" />"></script>
    <%@include file="/WEB-INF/jsp/inc/calendar.jsp"%>
</head>
<body>
<div class="list_right_title">
    <span><img src="<spring:url value="/static/images/im.jpg" htmlEscape="true" />" alt="信息管理"></span>产业服务>>信息编辑
</div>
<div class="fhq_add">
    <div class="fhq_add_in">
        <div class="fhq_add_form">
            <form:form modelAttribute="industryServiceInformation" method="${method}" enctype="multipart/form-data">
                <form:hidden path="id"/>
                <table class="fhq_add_table" cellpadding="0" cellspacing="" summary="产业服务>>信息编辑">
                    <tr>
                        <th width="20%">标题：</th>
                        <td width="80%">
                            <form:input path="title" cssClass="add_form_input"/>
                                <form:errors path="title" cssClass="error"/>
                        </td>
                    </tr>
                    <tr>
                        <th>文章类型：</th>
                        <td>
                            <form:select items="${allCategories}" path="industryService.id" itemValue="id"
                                         itemLabel="title" onchange="onChangeIndustryService();"/>
                        </td>
                    </tr>
                    <c:forEach var="categoryEntry" items="${allSubCategories}">
                        <tr style="display:none" id="subCategory_${categoryEntry.key}">
                            <th>文章子类型：</th>
                            <td>
                                <form:select items="${categoryEntry.value}" path="category.id" itemValue="id" id="subSelect_${categoryEntry.key}" itemLabel="name"/>
                            </td>
                        </tr>
                    </c:forEach>
                    <tr>
                        <th>摘要：</th>
                        <td>
                            <form:textarea path="summary" rows="3" cols="135"/>
                        </td>
                    </tr>
                    <tr>
                        <th>文章正文：</th>
                        <td>
                            <FCK:editor instanceName="EditorDefault" inputName="content" height="500"
                                        value="${industryServiceInformation.content}">
                            </FCK:editor>
                        </td>
                    </tr>
                    <tr>
                        <th>附件：</th>
                        <td>
                            <c:forEach items="${industryServiceInformation.attachmentList}" var="attachment"
                                       varStatus="status">
                                ${attachment.name} <input type="button" value="删除"
                                                          onclick="toDeleteAttachment(this, '${attachment.id}');"/>
                            </c:forEach>
                        </td>
                        <script type="text/javascript">
                            function toDeleteAttachment(el, attachmentId) {
                                if (el.value == "删除") {
                                    el.value = "恢复";
                                    var hiddenInput = document.createElement("INPUT");
                                    hiddenInput.id = "delAttachmentIds_" + attachmentId;
                                    hiddenInput.type = "hidden";
                                    hiddenInput.name = "delAttachmentIds";
                                    hiddenInput.value = attachmentId;
                                    document.getElementById("delIdsContainer").appendChild(hiddenInput);
                                } else {
                                    el.value = "删除";
                                    el.name = "attachmentList.id"
                                    var hiddenInput = document.getElementById("delAttachmentIds_" + attachmentId);
                                    document.getElementById("delIdsContainer").removeChild(hiddenInput);
                                }
                            }
                            function toAddAttachment() {
                                var firstAttachmentContainer = document.getElementById("firstAttachmentContainer");
                                var newAttachmentContainer = document.createElement("P");
                                firstAttachmentContainer.parentNode.appendChild(newAttachmentContainer);
                                newAttachmentContainer.innerHTML = '<input type="file" name="attachments" class="add_form_annex"><br/>附件大小不得大于5M 格式： TXT\\DOC\\ZIP\\RAR\\XLS\\JPG\\GIF，务必命名正确的附件名称';
                            }
                        </script>
                    </tr>
                    <tr style="display:none">
                        <td colspan="2" id="delIdsContainer">
                            <input type="hidden" name="delAttachmentIds" value="-1"/>
                        </td>
                    </tr>
                    <tr>
                        <th>附件：</th>
                        <td><input type="button" value="增加附件" onclick="toAddAttachment()"/></td>
                    </tr>
                    <tr>
                        <th style="padding-bottom:30px;">&nbsp;</th>
                        <td style="line-height:15px; color:#b6b6b6;">
                            <p id="firstAttachmentContainer">
                                <input type="file" name="attachments" class="add_form_annex">
                                <br/>附件大小不得大于5M 格式： TXT\DOC\ZIP\RAR\XLS\JPG\GIF，务必命名正确的附件名称
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <th>是否需要验证：</th>
                        <td>
                            <form:radiobutton path="accessPermission" value="1" label="是"/>
                            <form:radiobutton path="accessPermission" value="0" label="否"/>
                        </td>
                    </tr>
                    <tr>
                        <th>权值：</th>
                        <td>
                            <form:input path="orderCode"/>
                        </td>
                    </tr>
                    <tr>
                        <th>发布时间：</th>
                        <td>
                            <form:input path="publishDate" cssClass="fhq_add_select"/> 发布状态：
                            <form:select path="publishStatus" items="${allPublishStatus}" cssClass="fhq_add_select"/>
                        </td>
                    </tr>
                    <tr>
                        <th>发布人：</th>
                        <td>
                            admin
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td style="padding-top:20px;">
                            <!--<input type="button" value=" 保存并报送 ">　　　-->
                            <input type="submit" value=" 保存 ">　　　
                            <input type="button" value=" 返回 " onclick="window.location.href='search'">
                        </td>
                    </tr>
                </table>
            </form:form>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function onChangeIndustryService() {
        var industryServiceSelect = document.getElementById("industryService.id");
        var options = industryServiceSelect.options;
        if (!options) return;
        if (options.length) {
            for (var i = 0; i < options.length; i ++) {
                document.getElementById("subSelect_"+options[i].value).name = "";
                document.getElementById("subCategory_"+options[i].value).style.display = "none";
            }
        }

        document.getElementById("subSelect_"+industryServiceSelect.value).name = "category.id";
        document.getElementById("subCategory_"+industryServiceSelect.value).style.display = "";
    }
    onChangeIndustryService();
</script>
